//
//  StaticTapScene.cpp
//  CanYouDoIt
//
//  Created by hoangtx on 7/6/13.
//
//

#include "StaticTapScene.h"
#include "SceneManager.h"
#include "GameLayerManager.h"
CCScene* StaticTapScene::scene(int numberOfSeconds){
    // 'scene' is an autorelease object
    CCScene *scene = CCScene::create();
    
    // 'layer' is an autorelease object
    StaticTapScene *layer = StaticTapScene::create(numberOfSeconds);
    GameLayerManager::sharedInstance()->staticTapLayer = layer;
    
    // add layer as a child to scene
    scene->addChild(layer);
    
    // return the scene
    return scene;
}


bool StaticTapScene::init(){
    
    CountDownGameScene::init();
    
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    double buttonWidth = winSize.width * 0.7f;
    
    button = MySpriteButton::create("circle_button.png", (winSize.width - buttonWidth)/2, ((winSize.height - scoreAndTimeLayer->getBarHeight()-buttonWidth)/2), buttonWidth, buttonWidth);
    CCCallFuncO* callBackOnTap = CCCallFuncO::create(this, callfuncO_selector(StaticTapScene::onTapTheButton), this);
    button->addCallback(callBackOnTap);
    this->addChild(button,1);

    
    return true;
}

StaticTapScene* StaticTapScene::create(int numberOfSeconds){
    StaticTapScene* scene = StaticTapScene::create();
    scene->maxTimeCountDown = numberOfSeconds;
    scene->timeRemaining = scene->maxTimeCountDown;
    scene->scoreAndTimeLayer->updateTime(scene->timeRemaining);
    return scene;
}


#pragma mark - startGame
//SceneManager::sharedInstance()->previousScene = SceneManager::sharedInstance()->staticTapScene;

void StaticTapScene::onTapTheButton(cocos2d::CCObject *sender){
    
    numberOfTap++;
    scoreAndTimeLayer->updateScore(numberOfTap);
}

void StaticTapScene::startGame(){
    CountDownGameScene::startGame();
    SceneManager::sharedInstance()->previousScene = SceneManager::sharedInstance()->staticTapScene;

}

void StaticTapScene::reset(){
    CountDownGameScene::reset();
    button->resetState();
}


#pragma mark - event handling


void StaticTapScene::ccTouchesBegan(cocos2d::CCSet *touches, cocos2d::CCEvent *pEvent){
    button->handleTouchesBegan(touches, pEvent);
}

void StaticTapScene::ccTouchesMoved(cocos2d::CCSet *touches, cocos2d::CCEvent *pEvent){
    button->handleTouchesMoved(touches, pEvent);
}

void StaticTapScene::ccTouchesEnded(cocos2d::CCSet *touches, cocos2d::CCEvent *pEvent){
    button->handleTouchesEnded(touches, pEvent);
}